package com.dhcc.sdc.cdss.controller;


import java.util.List;
import java.util.Map;


import com.dhcc.sdc.cdss.entity.SdcCdssTreatEntity;
import com.dhcc.sdc.cdss.service.ISdcCdssTreatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;






/**
 * 
 * 
 * @ClassName: SdcCdssTreatController
 * @Description: TODO
 * @author zhangdc
 * @date 2022-06-23 15:46:45
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdccdsstreat")
public class SdcCdssTreatController extends BaseController {

	private String PREFIX = "/backend/sds/sdccdsstreat/";

	@Autowired
	private ISdcCdssTreatService sdcCdssTreatService;


    /**
     * 获取列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcCdssTreatEntity> page = new PageFactory<SdcCdssTreatEntity>().defaultPage();
        List<SdcCdssTreatEntity> result = this.sdcCdssTreatService.page(page,params);
        page.setRecords((List<SdcCdssTreatEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcCdssTreatEntity sdcCdssTreat) {
        if (CommonUtil.isOneEmpty(sdcCdssTreat)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcCdssTreat.insert();
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdcCdssTreatId) {
	
        this.sdcCdssTreatService.deleteById(sdcCdssTreatId);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcCdssTreatEntity sdcCdssTreat) {
        if (CommonUtil.isOneEmpty(sdcCdssTreat)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcCdssTreatEntity old = this.sdcCdssTreatService.selectById(sdcCdssTreat.getId());

        old.setItemId(sdcCdssTreat.getItemId());
        old.setQcentityId(sdcCdssTreat.getQcentityId());
        old.setItemName(sdcCdssTreat.getItemName());
        old.setItemDesc(sdcCdssTreat.getItemDesc());
        old.setSourceFlag(sdcCdssTreat.getSourceFlag());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
